package com.example.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.inter.LoginCallBack;
import com.example.myapplication.R;
import com.example.util.WorkInfoByIdUtil;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * A simple {@link Fragment} subclass.
 */
public class WorkInfoadviceFragment extends Fragment implements LoginCallBack {

    private TextView textView_title,textView_content;
    private WorkInfoByIdUtil workInfoByIdUtil;


    public WorkInfoadviceFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_work_infoadvice,container,false);
        initView(view);
        workInfoByIdUtil = new WorkInfoByIdUtil();
        Bundle bundle = getArguments();
        String  workid = bundle.getString("workid");
        workInfoByIdUtil.getInfo(workid,this);
        return view;
    }

    @Override
    public void onSuccess(String info) {
        try {
            JSONObject jsonObject = new JSONObject(info);
            JSONObject jsonObject1 = jsonObject.getJSONObject("info");
            String workname= jsonObject1.getString("workname");
            String workinfo = jsonObject1.getString("workinfo");
            textView_title.setText(workname);
            textView_content.setText(workinfo);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onFailed() {

    }
    private void initView(View view){

        textView_content = (TextView) view.findViewById(R.id.text_content);
        textView_title = (TextView) view.findViewById(R.id.text_title);
    }
}
